package com.xuyl.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuyl.domain.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

/**
 * @author nisemono
 * @date 2023-02-27 19:22
 */
@SpringBootTest
public class UserDaoTestCase {

    @Autowired
    private UserDao userDao;

    @Test
    void testAdd() {
        User user = new User();
        user.setName("xiaoming");
        user.setSex("1");
        user.setPhone("15277458923");
        user.setAddress("广东省广州市白云区");
        userDao.insert(user);
        System.out.println(user);
    }

    @Test
    void testUpdate() {
        User user = new User();
        user.setName("xiaohong");
        user.setSex("女");
        user.setPhone("15277458923");
        user.setVersion(1);
        user.setAddress("广东省广州市白云区");
        userDao.updateById(user);
    }

    @Test
    void testDelete() {
        userDao.deleteById(1);

    }

    @Test
    void testSelect() {
        IPage<User> page = new Page<>(1, 5);
        LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<>();
        User user = new User();
        user.setId(2);
        user.setName("xiaohong");
        user.setSex("女");
        user.setPhone("15277458923");
        user.setAddress("广东省广州市白云区");
        String val = "om";
        qw.like(user.getName() != null, User::getName, val)
                .or().like(user.getAddress() != null, User::getAddress, val);
        userDao.selectPage(page, qw);
        System.out.println(page.getRecords());
    }


}
